package main.java.indi.zyj.interview;

import java.util.concurrent.atomic.AtomicInteger;

public class Print100ABC {

    private static AtomicInteger atomicInteger = new AtomicInteger(0);

    public static void main(String[] args) {


        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 100; ) {
                if (atomicInteger.get() % 3 == 0) {
                    System.out.println("A");
                    atomicInteger.compareAndSet(atomicInteger.get(), atomicInteger.get() + 1);
                    i++;
                }
            }
        });
        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < 100; ) {
                if (atomicInteger.get() % 3 == 1) {
                    System.out.println("B");
                    atomicInteger.compareAndSet(atomicInteger.get(), atomicInteger.get() + 1);
                    i++;
                }
            }
        });
        Thread thread3 = new Thread(() -> {
            for (int i = 0; i < 100; ) {
                if (atomicInteger.get() % 3 == 2) {
                    System.out.println("C");
                    atomicInteger.compareAndSet(atomicInteger.get(), atomicInteger.get() + 1);
                    i++;
                }
            }
        });
        thread1.start();
        thread2.start();
        thread3.start();

    }

}
